dbprohelpfandomcom-20200215-history
Your Very First Program
'Return to Dark Basic Professional Beginner’s Tutorials' Making your first Dark Basic Pro program takes barely a few keystrokes. Start up DBP and you should be presented with this: Rem Project: Dark Basic Pro Project Rem Created: Thursday, July 19, 2012 Rem ***** Main Source File ***** This is just a header and because the text is Green we can tell it doesn't do anything at all. You don't need to worry about it just yet. First, go up to the taskbar at the top of Dark Basic and click the menu marked 'Compile' and select 'Compile and Run'. You should notice two things when you do this: first, the window at the bottom of the program marked ‘Output’ should have started to list numbered tasks like ‘cleaning up’ and so on. When it gets to ‘Execute’ '''you should see a black box appear in the middle of the screen for a fraction of a second and then vanish without doing anything. '''Here is what you just did in sequence: #You told DBP that you wanted to compile your raw code into a computer program #Because computers do only what you tell them to do - and nothing more or less - the ‘compiler’ (that is to say Dark Basic Pro) read through everything on the page and turned it into a program. #Because you didn’t tell it to do anything, DBP created a blank program that ran for half a second and then vanished. To get DBP to do something, you have to tell it what you want, so let’s start with every coding teacher’s favourite first program Hello World. To make this program type the following on a new line bellow the green text. Make sure you type it EXACTLY as shown otherwise it won’t work, and don’t copy and paste it as typing will help you remember what you are doing! Here is the code: Print "Hello World!" Now go and press the compile button again and see what happens! Notice anything? You should have seen the black window appear again for a moment and then vanish. Don’t panic, this was intentional. Let’s run through the sequence again to show what happened: #You wrote a program telling DBP to ‘Print’ the phrase “Hello World!” and compiled it. #Because computers do only what you tell them to do DBP read this command and turned it into a program displaying those words on the screen. #Because it wasn’t told to do anything else, when it hit the end of the program it just closed (if it didn’t do this none of your programs would ever close). #As computers are very fast you barely saw this happen. In order to get your program to stay on the screen it has to be told to do something. For example, one of the things we could tell it to do is to 'Wait'. Of course, because computers do only what you tell them, just telling them to ‘Wait’ would mean your program would wait forever! Because of this we need to tell it to ‘Wait’ for something specific, for example we could tell it to ‘Wait’ for us to press a ‘Key’ on the keyboard, so go ahead and type the following on a new line: Wait Key Compile your program, and you should see your message as a simple line of text. If you did it right, congratulations! You have just made your first computer program! It should look like this in DBP: Print "Hello World!" Wait Key That was pretty simple wasn't it? You should be ready for the next step in this tutorial now. Have fun!